package Controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Information.CV;
import Information.HireInfo;
import Model.CVDAO;

public class updateCV extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public updateCV() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ArrayList<CV> cvArrayList = new ArrayList<CV>();
		HttpSession session = request.getSession();
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String UUser = (String)session.getAttribute("username");
		int CVNO = 0;
		short USex =0;
		String UEmail=null;
		int UTel=0;
		String UAddress=null;
		int UPostCode=0;
		String Education=null;
		String Speciality=null;
		String JType=null;
		String Job=null;
		String City=null;
		int Expectation=0;
		String SelfIntroduction=null;
		CVDAO cvdao = new CVDAO();
		try {
			cvArrayList = cvdao.SeeCVByUUser(UUser);
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String result = "";
		for(CV cv : cvArrayList)
		{
			result+="<div class='panel panel-primary'>";
			result+="<form role='form' id='CVForm' method='post' action='updateCVNow'>";
			result+="<div class='form-group' id='CVNODiv'><label for='CVNO'>简历编号</label><h3 class='form-control' id='CVNO' name='CVNO' value='"+cv.getCVNO()+"'></h3></div>";
			result+="<div class='form-group' id='UUserDiv'><label for='UUser'>用户名</label><input type='text' class='form-control' id='UUser' name='UUser' value='"+cv.getUUser()+"'></div>";
			result+="<div class='form-group' id='USexDiv'><label for='USex'>性别</label><input type='text' class='form-control' id='USex' name='USex' value='"+cv.getUSex()+"'>";
			result+="<select class='form-control' id='USex' name='USex'><option>女</option><option>男</option></select></div>";
			
			result+="<div class='form-group' id='UEmailDiv'><label for='UEmail'>个人邮箱</label><input type='email' class='form-control' id='UEmail' name='UEmail' value='"+cv.getUEmail()+"'></div>";
			result+="<div class='form-group' id='UTelDiv'>"
					+"<label for='UTel'>电话</label>"
				+"<input type='tel' class='form-control' id='UTel' name='UTel' value='"+cv.getUTel()+"'></div>";
			result+="<div class='form-group' id='UAddressDiv'>"
				+"<label for='UAddress'>地址</label>"
				+"<input type='text' class='form-control' id='UAddress' name='UAddress' value='"+cv.getUAddress()+"'></div>";
			
			result+="<div class='form-group' id='UPostCodeDiv'>"
				+"<label for='UPostCode'>邮编</label>"
				+"<input type='tel' class='form-control' id='UPostCode' name='UPostCode' value='"+cv.getUPostCode()+"'></div>";
			result+="<div class='form-group' id='EducationDiv'>"
				+"<label for='Education'>教育程度</label>"
				+"<input type='text' class='form-control' id='Education' name='Education' value='"+cv.getEducation()+"'></div>";
			result+="<div class='form-group' id='SpecialityDiv'>"
				+"<label for='Speciality'>特长</label>"
				+"<input type='text' class='form-control' id='Speciality' name='Speciality' value='"+cv.getSpeciality()+"'></div>";
			result+="<div class='form-group' id='JTypeDiv'>"
				+"<label for='JType'>工作类型</label>"
				+"<input type='text' class='form-control' id='JType' name='JType' value='"+cv.getJType()+"'></div>";
			result+="<div class='form-group' id='JobDiv'>"
				+"<label for='Job'>工作职位</label>"
				+"<input type='text' class='form-control' id='Job' name='Job' value='"+cv.getJob()+"'></div>";
			
			result+="<div class='form-group' id='CityDiv'>"
				+"<label for='City'>工作城市</label>"
				+"<input type='text' class='form-control' id='City' name='City' value='"+cv.getCity()+"'></div>";
			
			result+="<div class='form-group' id='ExpectationDiv'>"
				+"<label for='Expectation'>期望工资(k/月)</label>"
				+"<input type='number' class='form-control' id='Expectation' name='Expectation' value='"+cv.getExpectation()+"'></div>";
			result+="<div class='form-group' id='SelfIntroductionDiv'>"
				+"<label for='SelfIntroduction'>自我介绍</label>"
				+"<textarea class='form-control' name='SelfIntroduction' id='SelfIntroduction' cols='30' rows='10' value='"+cv.getSelfIntroduction()+"'></textarea></div>";
			
			result+="<button class='btn btn-default'  type='submit'>更新</button></form></div>";

		}
		
			
		out.println(result);
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
